<?php

namespace Library;

use Doctrine\ORM\Mapping as Orm;

/**
 * @ORM\MappedSuperclass
 */
class BaseEntity
{
    
    /**
     * @ORM\Column(name="is_deleted", type="boolean", nullable=true, options={"default"= 0})
     */
    protected $deleted;
    
    /**
     * @ORM\Column(name="deleted_time", type="bigint", nullable=true)
     */
    protected $deletedTime;
    
    /**
     * @ORM\Column(name="created", type="bigint", nullable=true, options={"default"= 0})
     */
    protected $created;
    
    /**
     * @ORM\Column(name="modified", type="bigint", nullable=true, options={"default"= 0})
     */
    protected $modified;
    
    /**
     * @ORM\Column(name="isActive", type="boolean", nullable=true, options={"default"= 1})
     */
    protected $isActive;
    
    
    
    public function __construct()
    {
        $this->deleted = 0;
        $this->isActive = 1;
    }

    /**
     * Set deleted
     *
     * @param boolean $deleted
     * @return Rating
     */
    public function setDeleted($deleted)
    {
        $this->deleted = $deleted;
    
        return $this;
    }

    /**
     * Get deleted
     *
     * @return boolean 
     */
    public function isDeleted()
    {
    	return $this->deleted;
    }

    /**
     * Get deleted
     *
     * @return boolean 
     */
    public function getDeleted()
    {
        return $this->deleted;
    }
    
    /**
     * Set deleted time as current time
     * 
     * @return \Library\BaseEntity
     */
    public function setDeletedTime()
    {
        $this->deletedTime = time();
        
        return $this;
    }
    
    /**
     * Set deleted time to null
     * 
     * @return \Library\BaseEntity
     */
    public function resetDeletedTime()
    {
        $this->deletedTime = null;
        
        return $this;
    }
    
    /**
     * Get deletedTime
     * @return integer
     */
    public function getDeletedTime()
    {
        return $this->deletedTime;
    }

    public static function getClassName() 
    {
        return get_called_class();
    }

    public function getCreated()
    {
        return $this->created;
    }

    public function setCreated($created)
    {
        $this->created = $created;
        return $this;
    }

    public function getModified()
    {
        return $this->modified;
    }

    public function setModified($modified)
    {
        $this->modified = $modified;
        return $this;
    }
    
    public function getIsActive()
    {
        return $this->isActive;
    }
    
    public function setIsActive($isActive)
    {
        $this->isActive = $isActive;
        return $this;
    }
 
    /**
     * Count the number of undeleted childrens
     *
     * @param type $items
     * @return int
     */
    public static function count($items)
    {
        $count = 0;
        foreach ($items as $item) {
            if (is_a($item, 'Library\BaseEntity') && !$item->isDeleted()) {
                $count++;
            }
        }
        return $count;
    }


 
    

}

